package it.polimi.traveldream.dto;

import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

import javax.validation.constraints.Future;
import javax.validation.constraints.NotNull;

public class CartPackageDTO {

	private Integer id;

	private String city;

	private Integer duration;

	private Float price;

	private AccomodationDTO accomodation;

	private TransportDTO going;

	private TransportDTO back;

	private Map<Integer, ScheduleDTO> schedule;

	private Integer quantity;

	@NotNull
	@Future
	private Date date;

	private DetailedDefaultPackageDTO model;

	private Boolean purchased;

	public CartPackageDTO() {
		this.purchased = false;
		this.accomodation = new AccomodationDTO();
		this.going = new TransportDTO();
		this.back = new TransportDTO();
		this.schedule = new HashMap<>();
		this.date = new Date();
		this.quantity = 1;
	}

	public CartPackageDTO(DetailedDefaultPackageDTO packageDTO) {
		this.setPurchased(false);
		this.setAccomodation(packageDTO.getAccomodation());
		this.setBack(packageDTO.getBack());
		this.setGoing(packageDTO.getGoing());
		this.setSchedule(packageDTO.getSchedule());
		this.setCity(packageDTO.getCity());
		this.setDuration(packageDTO.getDuration());
		this.setModel(packageDTO);
		this.setPrice(packageDTO.getPrice());
		this.setQuantity(1);
	}

	public Integer getId() {
		return this.id;
	}

	public void setId(Integer id) {
		this.id = id;
	}

	public String getCity() {
		return this.city;
	}

	public void setCity(String city) {
		this.city = city;
	}

	public Integer getDuration() {
		return this.duration;
	}

	public void setDuration(Integer duration) {
		this.duration = duration;
	}

	public Float getPrice() {
		Float sum = this.getGoing().getPrice() + this.getBack().getPrice()
				+ (this.getAccomodation().getPrice() * this.getDuration());
		for (ScheduleDTO scheduleDTO : this.getSchedule().values()) {
			sum += scheduleDTO.getActivity().getPrice();
		}
		return sum;
		// return price;
	}

	public void setPrice(Float price) {
		this.price = price;
	}

	public AccomodationDTO getAccomodation() {
		return this.accomodation;
	}

	public void setAccomodation(AccomodationDTO accomodation) {
		this.accomodation = accomodation;
	}

	public TransportDTO getGoing() {
		return this.going;
	}

	public void setGoing(TransportDTO going) {
		this.going = going;
	}

	public TransportDTO getBack() {
		return this.back;
	}

	public void setBack(TransportDTO back) {
		this.back = back;
	}

	public Map<Integer, ScheduleDTO> getSchedule() {
		return this.schedule;
	}

	public void setSchedule(Map<Integer, ScheduleDTO> schedule) {
		this.schedule = schedule;
	}

	public Integer getQuantity() {
		return this.quantity;
	}

	public void setQuantity(Integer quantity) {
		this.quantity = quantity;
	}

	public Date getDate() {
		return this.date;
	}

	public void setDate(Date date) {
		this.date = date;
	}

	public DetailedDefaultPackageDTO getModel() {
		return this.model;
	}

	public void setModel(DetailedDefaultPackageDTO model) {
		this.model = model;
	}

	public Boolean getPurchased() {
		return this.purchased;
	}

	public void setPurchased(Boolean purchased) {
		this.purchased = purchased;
	}

	public void addSchedule(ScheduleDTO scheduleDTO) {
		this.getSchedule().put(scheduleDTO.getDay(), scheduleDTO);
	}

	public void setDate(Calendar date) {
		this.date = date.getTime();
	}

}
